************************************************
* Sleep Project - Pedro Bessone, Gautam Rao, Heather Schofield, Frank Schilbach, and Mattie Toma
* Purpose: Replicates Appendix Figure 1 (Fraction in Asleep and in Bed by Hour of Night)
* Last edited: 07 May 2021
************************************************

use "$d/epoch_dataset.dta", clear		

local minutes_bin "30"

		*Asleep graph
		#d;
		graph twoway (line asleep indicator_bin_`minutes_bin' if treatment_group == 0, lcolor(black) lpattern(dash) sort)
			(line asleep indicator_bin_`minutes_bin' if treatment_group == 1, lcolor(red) lpattern(longdash) sort)
			(line asleep indicator_bin_`minutes_bin' if treatment_group == 2, lcolor(blue) lpattern(shortdash) sort),
			graphregion(fcolor(white))
			xlabel(-60 "8PM" 60 "10PM" 180 "12PM" 300 "2AM" 420 "4AM" 540 "6AM" 680 "8AM" 800 "10AM", labsize(small))  ylabel(0(.2)1, labsize(small))
			xtitle("Hour at Night", height(-12)) ytitle("Fraction Asleep") yscale (r(0 1)) xsize(1.6) ysize(1)
			name(asleep, replace) legend(order(1 "Control" 2 "Devices + Encouragement" 3 "Devices + Incentives") region(col(white)) col(1) position(5) size(medium)) aspect(.5)
		;#d cr

			graph export "$oa/Figures/Figure_A1/asleep_by_hour_`minutes_bin'.eps", replace		
			graph export "$oa/Figures/Figure_A1/asleep_by_hour_`minutes_bin'.png", replace
		
		*Inbed graph
		#d;
		graph twoway (line in_bed indicator_bin_`minutes_bin' if treatment_group == 0, lcolor(black) lpattern(dash) sort)
			(line in_bed indicator_bin_`minutes_bin' if treatment_group == 1, lcolor(red) lpattern(longdash) sort)
			(line in_bed indicator_bin_`minutes_bin' if treatment_group == 2, lcolor(blue) lpattern(shortdash) sort),
			graphregion(fcolor(white))
			xlabel(-60 "8PM" 60 "10PM" 180 "12PM" 300 "2AM" 420 "4AM" 540 "6AM" 680 "8AM" 800 "10AM", labsize(small)) ylabel(0(.2)1, labsize(small))
			xtitle("Hour at Night") ytitle("Fraction in Bed") xsize(1.6) ysize(1)
			name(inbed, replace) legend(order(1 "Control" 2 "Devices + Encouragement" 3 "Devices + Incentives") region(col(white)) col(1) position(5) size(medium)) aspect(.5)
		;#d cr

			graph export "$oa/Figures/Figure_A1/in_bed_by_hour_`minutes_bin'.eps", replace		
			graph export "$oa/Figures/Figure_A1/in_bed_by_hour_`minutes_bin'.png", replace
